<?php $this->headScript()->appendFile($this->baseUrl().'/js/bootstrap-modal.js'); ?>
<?php
$this->title = "Recursos humanos";
echo $this->form_pesquisa;
?>

<p><a class="linkBtn" href="default/rh/form">Novo recurso humano</a></p>
<?php if(count($this->rh)): ?>
<table style="width:100%;">
    <tr>
        <th>Usuário</th>
        <th>Nome</th>
        <th>E-mail</th>
        <th>Cidade/UF</th>
        <th><a rel="tooltip" title="Acessar Moodle">M</a></th>
        <th><a rel="tooltip" title="Editar">A</a></th>
        <th><a rel="tooltip" title="Reiniciar senha">X</a></th>
        <th><a rel="tooltip" title="Excluir">E</a></th>
    </tr>
<?php
    $cont = 0;
    foreach($this->rh as $rechumano) :
        $cont++;
        if($cont % 2 == 0)
            echo '<tr class="even">';
        else
            echo '<tr class="odd">';
?>
        <td class="texto"><?php echo $this->escape($rechumano->username); ?></td>
        <td class="texto">
            <a href="default/rh/detalhe/id/<?php echo $rechumano->id; ?>">
            <?php echo $this->escape($rechumano->firstname.' '.$rechumano->lastname); ?>
            </a>
        </td>
        <td class="texto"><?php echo $this->escape($rechumano->email); ?></td>
        <td class="texto"><?php echo $this->escape($rechumano->city); if($rechumano->estado<>'--') { echo '/'.$this->escape($rechumano->estado); } ?></td>
        <td>
        <a href="https://anpnet.dpf.gov.br/user/view.php?id=<?php echo $rechumano->id; ?>" target="_blanck">
        <img alt="Moodle"  src="<?php echo $this->baseUrl().'/images/moodle.png'; ?>"></a>
        </td>
        <td>
        <a href="default/rh/form/id/<?php echo $rechumano->id; ?>">
        <img alt="Editar"  src="<?php echo $this->baseUrl().'/images/edit.png'; ?>"></a>
        </td>
        <td>
        <a style="cursor:pointer" onClick="mostrarModal('resetar_<?php echo $rechumano->id; ?>');">
        <img alt="Resetar"  src="<?php echo $this->baseUrl().'/images/eraser.png'; ?>"/></a>
        </td>
        <td>
        <a href="default/rh/delete/id/<?php echo $rechumano->id; ?>">
        <img alt="Excluir"  src="<?php echo $this->baseUrl().'/images/trash.png'; ?>"></a>
        </td>
<?php echo "</tr>"; endforeach; ?>
</table>

<?php foreach($this->rh as $rechumano) : ?>
        <div class="modal fade" 
                id="resetar_<?php echo $rechumano->id; ?>"
                style="display: none;">
            <div class="modal-header">
                <a class="close" data-dismiss="modal">×</a>
                <h3>Reiniciar senha</h3>
            </div>
            <div class="modal-body">
                <p>Deseja reiniciar a senha de <?php echo $this->escape($rechumano->firstname.' '.$rechumano->lastname); ?>?</p>
            </div>
            <div class="modal-footer">
                <a href="default/rh/resetar/id/<?php echo $rechumano->id; ?>" class="btn btn-primary">Reiniciar senha</a>
                <a class="btn" data-dismiss="modal">Cancelar</a>
            </div>
        </div>   
<?php endforeach; ?>

<p><?php $total = count($this->rh); echo $this->plural($total, 'Apenas %s registro encontrado.','Foram encontrados %s registros.'); ?></p> 
<?php if($total==100){ ?>
    <p style="color:red;">* Existem mais de 100 registros que atendem sua consulta! </p>
<?php } ?>
    
<?php endif; ?>
<br/>


<script>
    $('#email').focus();
    $('a').tooltip();

    function mostrarModal(id)
    {
        $('#'+id).modal({
            backdrop:false, show: true
        })
    }
</script>

